﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YCMS.Domain.Abstract;
using YCMS.Domain.Entities;

namespace YCMS.Domain.Concrete
{
    public class EFMemberRepository : IMemberRepository, IDisposable
    {
        private EfDbContext context;

        public EfDbContext Context
        {
            get
            {
                return context;
            }
            set
            {
                context = value;
            }
        }

        public IQueryable<Member> Members
        {
            get
            {
                return context.Member;
            }
        }

        public Member GetMemberByID(int id)
        {
            Member m = context.Member.Find(id);
            return m;
        }

        public void InsertMember(Member member)
        {
            context.Member.Add(member);
        }

        public void Save()
        {
            context.SaveChanges();
        }

        public void UpdateMember(Member member)
        {
            context.Entry(member).State = System.Data.EntityState.Modified;
        }

        public void DeleteMember(Member member)
        {
            context.Member.Find(member.ID);
            context.Member.Remove(member);
        }



        private bool disposed = false;

        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    context.Dispose();
                }
            }
            this.disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        } 

    }
}
